﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Green.FastInvoker;

namespace Green.AgileMapper
{
    public class DataRowMappingConfigurator : IMappingConfigurator
    {

        #region IMappingConfigurator 成员

        public bool IsNeedCache
        {
            get { return false; }
        }

        public IMappingRule[] GetMappingRule(object from)
        {
            var row = from as DataRow;
            if (row != null && row.Table != null)
            {
                return row.Table.Columns.Cast<DataColumn>().Select(t => new DataRowMappingRule(t.ColumnName, t.ColumnName)).ToArray();
            }

            return PropertyAccessor.GetPropertys(from).Select(t => new DataRowMappingRule(t.Name, t.Name)).ToArray();
        }

        public string GetConfigurationName()
        {
            return "DataRowMapping";
        }

        #endregion

        #region IMappingConfigurator 成员

        public Func<object, object, bool> DefaultEqualExpression
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }
}
